package entity

import (
	"sync"
	"sync/atomic"
	"time"
)

type Boss struct {
	sync.Mutex `sql:"-"`
	ServerID   int32 `gorm:"primary_key;AUTO_INCREMENT"`
	MaxHP      int64
	HP         int64
	IsSave     bool // 是否已保存
	Killer     int32
	KillerName string // 最后一击的玩家名称
	CreatedAt  time.Time
	UpdatedAt  time.Time

	PublishHP int64           `sql:"-"` // 推送数据时的HP
	AtkTime   time.Time       `sql:"-"` // 最后攻击时间 2秒内就推送
	Damages   map[int32]int64 `sql:"-"`
}

//func (b *Boss) InitHP(dB *gorm.DB) {
//
//	b.MaxHP = dB.FirstOrCreate()
//	b.HP = b.MaxHP
//}

func (b *Boss) SubHP(hp int64) int64 {

	return atomic.AddInt64(&b.HP, -hp)
}

func (b *Boss) GetHP() int64 {

	if b.HP < 0 {
		b.HP = 0
	}
	return b.HP
}
